package com.shop.servlet.product;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.entity.Product;
import com.shop.service.ProductService;

/**
 * Servlet implementation class ProductSearch
 */
@WebServlet("/Search")
public class ProductSearch extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProductSearch() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		

		//页面传回参数 要查的值
			String searchWord = request.getParameter("searchWord");
			//开始查询
			ProductService ProductService=new ProductService(); 
			List<Product> list=ProductService.getProductsByWord(searchWord);
			request.setAttribute("products", list);
			request.getRequestDispatcher("search.jsp").forward(request, response);
			return;

			
	
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
